﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SOM.Model;
using System.Windows.Forms;
using SOM.UI;

namespace SOM.Control
{
    public class MainWindowCtrl
    {
        private CompositionalSpectrum CSpectrum;
        internal SOMNetwork sofm;
        private nGrammDictionary nGramDict;
        private MainWindow mainForm;
        private string examplesFolderPath;
        private int dictionarySize;
        private int letterMismatch;
        private int NGramLength;
        private int EpochNum;
        private int tessalationLvl;
        private double learningRate;
        private double KernelWidth;

        public MainWindowCtrl(MainWindow mainFormArg)
        {
            this.mainForm = mainFormArg;
        }

        public SOMNetwork SOFM
        {
            get
            {
                return this.sofm;
            }
        }

        internal void createFrequencyVectors(string folderName,int lenNgram,int sizeDict, int mismatch)
        {
            nGramDict = new nGrammDictionary(lenNgram, sizeDict);
            this.CSpectrum = new CompositionalSpectrum(folderName, nGramDict, mismatch,this);
        }

        internal void runAnalysis()
        {
            createFrequencyVectors(examplesFolderPath, NGramLength, dictionarySize, letterMismatch);
            this.sofm = new SOMNetwork(CSpectrum, tessalationLvl, EpochNum, learningRate, KernelWidth,this);
            this.sofm.init();
            this.sofm.trainSOM();
            this.sofm.calculateInputPatternsColors(0);
        }

        internal void setAnalysisRunParams(string folderName, int lenNgram, int sizeDict, int mismatch,int Epochs , int tessalation,double learnRate, double kWidth)
        {
            this.examplesFolderPath = folderName;
            this.dictionarySize = sizeDict;
            this.letterMismatch = mismatch;
            this.NGramLength = lenNgram;
            this.EpochNum = Epochs;
            this.tessalationLvl = tessalation;
            this.learningRate = learnRate;
            this.KernelWidth = kWidth;
        }

        public void SetProgressBarValue(int progress)
        {
            mainForm.BGWORKER.ReportProgress(progress);
        }
    }
} 
